package com.xm.factory;

/**
 * 抽象工厂模式
 */
public class CAbstract {
    public static void main(String[] args) {
        GUIFactory factory = new MacOSFactory();
        Button button = factory.createButton();
        TextField textField = factory.createTextField();
        button.render();      // 输出: MacOS风格按钮
        textField.display();  // 输出: MacOS风格文本框
    }
}
// 1. 抽象产品族接口
interface Button {
    void render();
}

interface TextField {
    void display();
}

// 2. 具体产品族（Windows风格）
class WindowsButton implements Button {
    @Override
    public void render() {
        System.out.println("Windows风格按钮");
    }
}

class WindowsTextField implements TextField {
    @Override
    public void display() {
        System.out.println("Windows风格文本框");
    }
}

// 3. 具体产品族（MacOS风格）
class MacOSButton implements Button {
    @Override
    public void render() {
        System.out.println("MacOS风格按钮");
    }
}

class MacOSTextField implements TextField {
    @Override
    public void display() {
        System.out.println("MacOS风格文本框");
    }
}

// 4. 抽象工厂接口
interface GUIFactory {
    Button createButton();
    TextField createTextField();
}

// 5. 具体工厂
class WindowsFactory implements GUIFactory {
    @Override
    public Button createButton() {
        return new WindowsButton();
    }

    @Override
    public TextField createTextField() {
        return new WindowsTextField();
    }
}

class MacOSFactory implements GUIFactory {
    @Override
    public Button createButton() {
        return new MacOSButton();
    }

    @Override
    public TextField createTextField() {
        return new MacOSTextField();
    }
}